package com.work.washer.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.work.washer.dto.SendReq;
import com.work.washer.mapper.ChatMapper;
import com.work.washer.model.Chat;
import com.work.washer.model.Keyword;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author cys
* @description 针对表【chat】的数据库操作Service
* @createDate 2024-04-26 18:23:48
*/
@Service
public class ChatService extends ServiceImpl<ChatMapper, Chat>
    implements IService<Chat> {

    @Autowired
    private KeywordService keywordService;


    public void say(SendReq req) {
        Chat chat = new Chat();
        chat.setUserId(req.getUserId());
        chat.setType(1);
        chat.setContent(req.getContent());
        chat.setCreateDate(new Date());
        save(chat);
        Keyword one = keywordService.lambdaQuery().like(Keyword::getKeyword, req.getContent()).one();
        if(one == null){
            Chat chat2 = new Chat();
            chat2.setUserId(1);
            chat2.setType(1);
            chat2.setContent("请稍后");
            chat2.setCreateDate(new Date());
            save(chat2);
        }else{
            Chat chat2 = new Chat();
            chat2.setUserId(1);
            chat2.setType(1);
            chat2.setContent(one.getContent());
            chat2.setCreateDate(new Date());
            save(chat2);
        }
    }
}
